.\" (c) 1998-2018 by Columbia University; all rights reserved
.\" (c) 2017-2018 by Jan Stary <hans@stare.cz>
.\"
.\" SPDX-License-Identifier: BSD-3-Clause
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.Dd June 25, 2018
.Dt RTPDUMP 1
.Os
.Sh NAME
.Nm rtpdump
.Nd parse and print RTP packets
.Sh SYNOPSIS
.Nm
.Op Fl h
.Op Fl F Ar format
.Op Fl f Ar infile
.Op Fl o Ar outfile
.Op Fl t Ar minutes
.Op Fl x Ar bytes
.Oo Ar address Oc Ns / Ns Ar port
.Sh DESCRIPTION
.Nm
reads RTP and RTCP packets on the given
.Ar address Ns / Ns Ar port ,
or from standard input by default,
and dumps a processed version to standard output.
The output is suitable as input for
.Xr rtpplay 1
and
.Xr rtpsend 1 .
The IPv4
.Ar address
can be specified in dotted decimal notation or as a hostname
and defaults to
.Dq localhost .
The
.Ar port
number must be an even number.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl F Ar format
Write the output in the given
.Ar format ,
which is one of the following:
.Cm dump ,
.Cm header ,
.Cm payload ,
.Cm ascii ,
.Cm hex ,
.Cm rtcp ,
.Cm short .
.Pp
The
.Cm dump
format is a binary format suitable as input for
.Xr rtpplay 1 .
The generated output file should have a
.Pa .rtp
filename extension.
The file starts with
.Pp
.Dl #!rtpplay1.0 address/port\en
.Pp
The version number indicates the file format version,
not the version of RTP tools used to generate the file.
The current file format version is 1.0.
This is followed by one
.Vt RD_hdr_t
header and one
.Vt RD_packet_t
structure for each received packet.
All fields are stored in the network byte order.
This metadata is followed by the actual RTP or RTCP packet, recorded as-is.
The structures are as follows:
.Bd -literal
typedef struct {
  struct timeval start;  /* start of recording (GMT) */
  uint32_t source;       /* network source (multicast) */
  uint16_t port;         /* UDP port */
} RD_hdr_t;

typedef struct {
  uint16_t length; /* length of original packet, including header */
  uint16_t plen;   /* actual header+payload length for RTP, 0 for RTCP */
  uint32_t offset; /* ms since the start of recording */
} RD_packet_t;
.Ed
.Pp
The
.Cm header
format is like
.Cm dump ,
but does not save the audio/video payload.
The
.Cm payload
format only saves the audio/video payload.
.Pp
The
.Cm ascii
format, which is the default, saves text parsed packets,
suitable for
.Xr rtpsend 1 .
Each entry starts with a time value, in seconds, relative to the beginning.
The time value appears at the beginning of a line, without white space.
Within an RTP or RTCP packet description, parameters may appear in any order,
without white space around the equal sign.
Lines are continued with initial white space on the next line.
Comment lines start with
.Sq # .
Strings are enclosed in quotation marks.
The actual RTP and RTCP entries look like this:
.Bd -literal
<time> RTP
	v=<version>
	p=<padding>
	x=<extension>
	m=<marker>
	pt=<payload type>
	ts=<time stamp>
	seq=<sequence number>
	ssrc=<SSRC>
	cc=<CSRC count>
	csrc=<CSRC>
	data=<hex payload>
	ext_type=<type of extension>
	ext_len=<length of extension header>
	ext_data=<hex extension data>
	len=<packet size in bytes (including header)>
.Ed
.Bd -literal
<time> RTCP
	(SDES v=<version> (src=<source> cname="..." name="...") (...))
	(SR v=<version>
		ssrc=<SSRC of data source>
		p=<padding>
		count=<number of sources>
		len=<length>
		ntp=<NTP timestamp>
		psent=<packet sent>
		osent=<octets sent>
		(ssrc=<SSRC of source>
			fraction=<loss fraction>
			lost=<number lost>
			last_seq=<last sequence number>
			jit=<jitter>
			lsr=<last SR received>
			dlsr=<delay since last SR>
		)
	)
.Ed
.\" FIXME: describe the individual fields
.Pp
The
.Cm hex
format is like
.Cm ascii ,
but with a hex dump of the payload.
The
.Cm rtcp
format is like
.Cm ascii ,
but only saves RTCP packets.
.Pp
The
.Cm short
format dumps RTP or VAT data in lines such as
.Pp
.D1 Oo Cm - Oc Ns Ar time timestamp Op Ar seq
.Pp
where
.Sq Cm -
indicates a set marker bit,
.Ar time
is the arrival time,
.Ar timestamp
is the RTP timestamp, and
.Ar seq
is the RTP sequence number (only used for RTP packets).
.It Fl f Ar infile
Read packets from
.Ar infile
instead of the network or standard input.
The file must have been recorded using the
.Cm dump
format.
.It Fl h
Print a short usage summary and exit.
.It Fl o Ar outfile
Dump to
.Ar outfile
instead of to standard output.
.It Fl t Ar minutes
Only listen for the first
.Ar minutes .
.It Fl x Ar bytes
Process only the first number of
.Ar bytes
of each packet's payload.
This is only applicable for the
.Cm dump
and
.Cm hex
formats.
.El
.Sh EXAMPLES
.Bd -literal
$ rtpdump -F ascii < bark.rtp
44.020000 RTP len=172 from=0.0.0.0:0 v=2 p=0 x=0 cc=0 m=1 pt=0 (PCMU,1,8000) seq=54553 ts=3988999488 ssrc=0x59c72
44.030000 RTCP len=72 from=0.0.0.0:0
 (SR ssrc=0x59c72 p=0 count=0 len=6
  ntp=3167928311.3622222025 ts=3988999508 psent=1 osent=160
 )
 (SDES p=0 count=1 len=10
  (src=0x59c72 CNAME="good_dog@columbia.edu" NAME="nice_dog" )
 )
44.050000 RTP len=172 from=0.0.0.0:0 v=2 p=0 x=0 cc=0 m=0 pt=0 (PCMU,1,8000) seq=54554 ts=3988999648 ssrc=0x59c72
44.070000 RTP len=172 from=0.0.0.0:0 v=2 p=0 x=0 cc=0 m=0 pt=0 (PCMU,1,8000) seq=54555 ts=3988999808 ssrc=0x59c72
[...]
44.380000 RTP len=173 from=0.0.0.0:0 v=2 p=0 x=0 cc=0 m=0 pt=0 (PCMU,1,8000) seq=54567 ts=3989001728 ssrc=0x59c72
.Ed
.Bd -literal
$ rtpdump -F rtcp /1234
1529922419.410173 RTCP len=72 from=127.0.0.1:38874
 (SR ssrc=0x59c72 p=0 count=0 len=6
  ntp=3167928311.3622222025 ts=3988999508 psent=1 osent=160
 )
 (SDES p=0 count=1 len=10
  (src=0x59c72 CNAME="good_dog@columbia.edu" NAME="nice_dog" )
 )
.Ed
.Bd -literal
$ rtpdump -F short /1234
-1511433758.442892 3988999488 54553
1511433758.480881 3988999648 54554
1511433758.500863 3988999808 54555
1511433758.520860 3988999968 54556
1511433758.540872 3989000128 54557
.Ed
.Sh SEE ALSO
.Xr rtpplay 1 ,
.Xr rtpsend 1
.Sh AUTHORS
.An -nosplit
.Nm
was written by
.An Henning Schulzrinne Aq Mt hgs@cs.columbia.edu ,
with enhancements by
.An Ping Pan ,
.An Akira Tsukamoto Aq Mt akira.tsukamoto@gmail.com ,
.An Jan Stary Aq Mt hans@stare.cz ,
and
.An Jan Janak Aq Mt janakj@cs.columbia.edu .
